﻿using System;
using MongoDAO;
using MongoDAO.Providers;
using MongoDAOTest.Entities;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Driver;
using NUnit.Framework;

namespace MongoDAOTest.Providers
{
    [TestFixture]
    public class MongoCollectionProviderTests
    {
        private MongoDatabase _mongoDatabase;
        private MongoCollectionProvider _collectionProvider;

        [TestFixtureSetUp]
        public void FixtureSetUp()
        {
            _mongoDatabase = new MongoDatabaseProvider().GetDatabase();
            _collectionProvider = new MongoCollectionProvider(_mongoDatabase);
        }


        [Test]
        public void GetMongoCollection_Test()
        {
            var collection = _collectionProvider.GetCollection<Document>();
            Assert.IsNotNull(collection);
        }

        [Test]
        public void GetMongoCollection_Overload_Test()
        {
            var collection = _collectionProvider.GetCollection("Documents");
            Assert.IsNotNull(collection);
        }

        [Test]
        [ExpectedException(typeof(NullReferenceException))]
        public void MongoCollectionName_Obrigatório_Test()
        {
            var collection = _collectionProvider.GetCollection<FailDocument>();
        }
    }

    public class FailDocument : TDocument
    {
        [BsonId(IdGenerator = typeof(ObjectIdGenerator))]
        public override object Id { get; set; }
    }
}
